#pragma once
#include "circular_list.h"

class Josephus
{
private:
	circular_list cl;
public:

	Josephus()
	{
	}

	void insertNames()
	{
		cout << "Write name (write stop when done): " << endl;
		string name;
		string stop = "stop";
		getline(cin, name);

		while (name.compare(stop) != 0)
		{
			cl.addLast(name);
			cout << "Write name (write stop when done): " << endl;
			getline(cin, name);
		}
	}

	void playGame()
	{
		node* currentPerson = cl.GetSentinel().next;
		while (cl.oneRemaining() == false)
		{
			for (int i = 0; i < 2; i++)
			{
				if (currentPerson->next->value == cl.GetSentinel().value)
				{
					currentPerson = cl.GetSentinel().next;
				}
				else
				{
					currentPerson = currentPerson->next;
				}
			}
			node* temp = currentPerson->next;
			cl.remove(currentPerson->value);
			if (temp->value == cl.GetSentinel().value)
			{
				currentPerson = cl.GetSentinel().next;
			}
			else
			{
				currentPerson = temp;
			}
		}

		cout << "The last person standing is: " << cl.front() << endl;
	}

	~Josephus()
	{
	}
};

